package com.example.design.impl;

import com.example.design.core.EnhancedFileProcessor;
import com.example.design.core.FileMatchers;
import com.example.design.core.FileProcessingContext;
import com.example.design.core.ProcessorRegistration;
import com.example.design.utils.FileUtils;

import java.nio.file.Path;
import java.util.Arrays;
import java.util.List;

/**
 * 智能文件处理器实现
 */
public class SmartFileProcessor extends EnhancedFileProcessor<OrderFieldEnum> {

    @Override
    protected List<ProcessorRegistration<OrderFieldEnum>> getProcessorRegistrations() {
        return Arrays.asList(
                // 优先级 10：特殊 txt
                ProcessorRegistration.of(
                        FileMatchers.and(
                                FileMatchers.byExtension("txt"),
                                FileMatchers.byPrefix("SPECIAL_")
                        ),
                        this::processSpecialTxtFile,
                        10
                ),

                // 优先级 100：压缩文件
                ProcessorRegistration.of(
                        FileMatchers.byExtension("zip", "rar", "7z"),
                        this::processArchiveFile,
                        100
                ),

                // 优先级 200：图片文件
                ProcessorRegistration.of(
                        FileMatchers.byExtension("jpg", "png", "gif"),
                        this::processImageFile,
                        200
                ),

                // 默认普通 txt 文件
                ProcessorRegistration.of(
                        FileMatchers.byExtension("txt"),
                        this::processNormalTxtFile,
                        999
                )
        );
    }

    private void processSpecialTxtFile(Path file, String fileName, FileProcessingContext<OrderFieldEnum> context) {
        System.out.println("✅ 特殊TXT文件处理：" + fileName);
    }

    private void processNormalTxtFile(Path file, String fileName, FileProcessingContext<OrderFieldEnum> context) {
        System.out.println("📄 普通TXT文件处理：" + fileName);
    }

    private void processArchiveFile(Path file, String fileName, FileProcessingContext<OrderFieldEnum> context) {
        System.out.println("📦 压缩文件处理：" + fileName);
        System.out.println("生成批次号：" + FileUtils.generateBatchId());
    }

    private void processImageFile(Path file, String fileName, FileProcessingContext<OrderFieldEnum> context) {
        System.out.println("🖼️ 图片文件处理：" + fileName);
    }
}
